package it.unipd.dei.project.iandroid;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;

public class HelloTabWidget extends TabActivity implements OnTabChangeListener {

	TabHost tabHost;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.tabwidget);
		tabHost = getTabHost();
		TabHost.TabSpec spec;
		Intent intent;

		// Creo i tab dove verranno mostrate le squadre, gli eventi e il calendario
		intent = new Intent().setClass(this, TeamManager.class);

		spec = tabHost.newTabSpec("Squadre").setIndicator("Squadre", getResources().getDrawable(R.drawable.soccer_stadium))
				.setContent(intent);
		tabHost.addTab(spec);

		intent = new Intent().setClass(this, EventManager.class);
		spec = tabHost.newTabSpec("Eventi").setIndicator("Eventi", getResources().getDrawable(R.drawable.soccer_trophy))
				.setContent(intent);
		tabHost.addTab(spec);

		intent = new Intent().setClass(this, Calendar.class);
		spec = tabHost.newTabSpec("Calendario")
				.setIndicator("Calendario", getResources().getDrawable(R.drawable.calendario)).setContent(intent);
		tabHost.addTab(spec);

		tabHost.setCurrentTab(0);
		setTabColor(tabHost);
		tabHost.setOnTabChangedListener(this);
		tabHost.setBackgroundColor(android.graphics.Color.rgb(0xaa, 0xdd, 0xff));
	}

	@Override
	public void onTabChanged(String tabId) {
		if (tabId.equals("Squadre")) {
			tabHost.setBackgroundColor(android.graphics.Color.rgb(0xaa, 0xdd, 0xff));
		} else if (tabId.equals("Eventi")) {
			tabHost.setBackgroundColor(android.graphics.Color.rgb(0x41, 0xa3, 0x17));
		} else if (tabId.equals("Calendario")) {
			tabHost.setBackgroundColor(android.graphics.Color.rgb(0xdd, 0x33, 0x00));
		}
	}

	public void setTabColor(TabHost tabhost) {
		for (int i = 0; i < tabhost.getTabWidget().getChildCount(); i++) {

			TextView tv = (TextView) tabhost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); // Unselected
																																																			// Tabs
			tv.setTextSize(16);
			tv.setTypeface(null, 1);
			tv.setTextColor(getResources().getColorStateList(R.drawable.tab_text_color_selector));
		}
	}

}
